package com.pocket.insight.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import java.util.LinkedHashSet;


/**
 * 描述：
 *
 * @author shuize
 * @create 2024/12/13
 */
@Data
public class ParamAttrOptions {
    private Type.TypeName           type;
    private SubType                 subType;
    private  Object                  maxValue;
    private Object                  minValue;
    private LinkedHashSet<SetValue> valueSet;
    private Long                    intervalNum;
    private TimePeriod period;
    private String granularity;
    private Boolean isSingleElection;
    private Object defaultValue;
    private Object displayValue;
    @JsonIgnore
    private Object currentValue;
    private Boolean allowAllValue = false;
    private Source source;
    private MultiValueConfig multiValueConfig;

    @Data
    public static class SetValue {
        private Object value;
        private Object display;
    }

    @Data
    public static class MultiValueConfig {
        private Boolean enable;
        private String split;
        private String quote;
        private String prefix;
        private String suffix;
    }


    public enum Source {
        SYSTEM_DEFINE,
        CUSTOMER_DEFINE;
        Source() {
        }
    }

    public enum SubType {
        ALL,
        LIST,
        DYNAMIC,
        RANGE;
    }

    public enum TimePeriod {
        YEAR("year"),
        QUARTER("quarter"),
        MONTH("month"),
        WEEK("week"),
        DAY("day"),
        HOUR("hour"),
        MINUTE("minute"),
        SECOND("second");

        private String value;

        TimePeriod(String value) {
            this.value = value;
        }

        public String getValue() {
            return this.value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public static int getIntervalTruncateFieldByTimePeriod(TimePeriod period) {
            switch (period) {
                case YEAR:
                    return 1;
                case QUARTER:
                case MONTH:
                    return 2;
                case WEEK:
                case DAY:
                    return 5;
                case HOUR:
                    return 10;
                case MINUTE:
                    return 12;
                case SECOND:
                    return 13;
                default:
                    return 5;
            }
        }
    }
}
